package cn.itamt.stars {
	import cn.itamt.stars.base.IStar;
	import cn.itamt.stars.base.Star;

	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.geom.Rectangle;	

	/**
	 * 会移动的星星(行星?)
	 * @author tamt
	 */
	public class PlanetStar extends Star implements IStar {
		public var speedX : Number = 2;
		public var speedY : Number = 0;

		
		public function PlanetStar() {
		}

		override public function build(rendererClass : Class, rect : Rectangle, container : DisplayObjectContainer) : void {
			super.build(rendererClass, rect, container);
				
			x = _rect.left + _rect.width * Math.random();
			y = _rect.top + _rect.height * Math.random();
			speedX = .5 + Math.random() * 2;
		}

		override public function update() : void {
			x += speedX;
			y += speedY;
			
			if(x < _rect.left) {
				x = _rect.right;
			}else if(x > _rect.right) {
				x = _rect.left;
			}
			
			if(y < _rect.top) {
				y = _rect.bottom;
			}else if(y > _rect.bottom) {
				y = _rect.top;
			}
		}
	}
}
